package one.bugu.android.demon.ui.activity.wallet;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.juefeng.android.framework.view.annotation.LKContentView;
import com.juefeng.android.framework.view.annotation.LKInjectView;

import java.text.DecimalFormat;

import one.bugu.android.demon.R;
import one.bugu.android.demon.bean.BGTInfoBean;
import one.bugu.android.demon.common.MyBaseActivity;
import one.bugu.android.demon.ui.widget.BaseTopBarView;
import one.bugu.android.demon.util.StatusBarUtils;

/**
 * 钱包详情界面
 */
@SuppressLint("Registered")
@LKContentView(R.layout.activity_wallet_details)
public class WalletDetailsActivity extends MyBaseActivity {
    /**
     * topBar
     */
    @LKInjectView(R.id.btbv_wd_detail)
    private BaseTopBarView btbv_wd_detail;
    /**
     * 支出/收入
     */
    @LKInjectView(R.id.tv_wdt_type)
    private TextView tv_wdt_type;
    /**
     * 收支数量
     */
    @LKInjectView(R.id.tv_wdt_num)
    private TextView tv_wdt_num;
    /**
     * 收支单位
     */
    @LKInjectView(R.id.tv_wdt_name)
    private TextView tv_wdt_name;
    /**
     * 收支明细
     */
    @LKInjectView(R.id.tv_wdt_details)
    private TextView tv_wdt_details;
    /**
     * 提现详情
     */
    @LKInjectView(R.id.tv_wdt_draw_title)
    private TextView tv_wdt_draw_title;
    /**
     * 提现地址
     */
    @LKInjectView(R.id.iv_wdt_address_pick)
    private ImageView iv_wdt_address_pick;

    @LKInjectView(R.id.tv_wdt_address)
    private TextView tv_wdt_address;

    @LKInjectView(R.id.rl_wdt_address)
    private RelativeLayout rl_wdt_address;
    /**
     * 订单编号
     */
    @LKInjectView(R.id.rl_wdt_order)
    private RelativeLayout rl_wdt_order;

    @LKInjectView(R.id.tv_wdt_order_num)
    private TextView tv_wdt_order_num;

    /**
     * 申请时间
     */
    @LKInjectView(R.id.tv_wdt_apply_time)
    private TextView tv_wdt_apply_time;

    @LKInjectView(R.id.tv_wdt_apply_name)
    private TextView tv_wdt_apply_name;
    /**
     * 处理时间
     */
    @LKInjectView(R.id.tv_wdt_deal_time)
    private TextView tv_wdt_deal_time;

    @LKInjectView(R.id.rl_wdt_deal_time)
    private RelativeLayout rl_wdt_deal_time;
    /**
     * 备注
     */
    @LKInjectView(R.id.tv_wdt_remark)
    private TextView tv_wdt_remark;

    @LKInjectView(R.id.rl_wdt_remark)
    private RelativeLayout rl_wdt_remark;

    @LKInjectView(R.id.tv_wdt_remark_title)
    private TextView tv_wdt_remark_title;
    /**
     * 分割线
     */
    @LKInjectView(R.id.view_line)
    private View view_line;

    public static final String WALLET_DATA = "walletData";

    DecimalFormat df = new DecimalFormat("###.#####");

    private BGTInfoBean bgtInfoBean;

    @Override
    protected void initView() {
        super.initView();
        //设置状态栏
        StatusBarUtils.getInstance().setStatusBar(this, btbv_wd_detail);
    }

    @Override
    protected void initData() {
        super.initData();

        Intent intent = getIntent();
        if (intent != null) {
            bgtInfoBean = (BGTInfoBean) intent.getSerializableExtra(WALLET_DATA);
        }
        //设置数据
        setViewStatus();
        setViewData();
    }

    @Override
    protected void initEvent() {
        super.initEvent();
        btbv_wd_detail.setEventInterface(new BaseTopBarView.EventInterface() {
            @Override
            public void leftOnClick() {
                finish();
            }

            @Override
            public void leftCloseClick() {

            }

            @Override
            public void rightOnClick() {

            }
        });
        //提现地址
        iv_wdt_address_pick.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iv_wdt_address_pick.setSelected(!iv_wdt_address_pick.isSelected());
                tv_wdt_address.setVisibility(iv_wdt_address_pick.isSelected() ? View.VISIBLE : View.GONE);
            }
        });

    }

    /**
     * 设置不同状态
     */
    private void setViewStatus() {
        String typeName = bgtInfoBean.getWallteTypeName();
        if (TextUtils.equals(typeName, "BGT")) {
            //bgt详情
            boolean flag = "200".equals(bgtInfoBean.getTradeTypeId());

            rl_wdt_order.setVisibility(flag ? View.VISIBLE : View.GONE);
            tv_wdt_draw_title.setVisibility(flag ? View.VISIBLE : View.GONE);
            rl_wdt_remark.setVisibility(flag ? View.VISIBLE : View.GONE);
            view_line.setVisibility(flag ? View.VISIBLE : View.GONE);
            rl_wdt_address.setVisibility(View.GONE);
            tv_wdt_draw_title.setText("订单详情:");
            tv_wdt_apply_name.setText("订单时间");
            tv_wdt_remark_title.setText("活动期号");

            //申请处理时间  暂时不使用
            rl_wdt_deal_time.setVisibility(View.GONE);
        } else {
            //eth详情
            boolean flag = "300".equals(bgtInfoBean.getTradeTypeId())
                    || "302".equals(bgtInfoBean.getTradeTypeId());
            boolean isDraw = "300".equals(bgtInfoBean.getTradeTypeId());

            tv_wdt_draw_title.setText("提现详情:");
            tv_wdt_draw_title.setVisibility(flag ? View.VISIBLE : View.GONE);
            tv_wdt_apply_name.setText(flag ? (isDraw ? "申请提现时间" : "提现处理时间") : "订单时间");
            tv_wdt_remark_title.setText("备注");
            rl_wdt_address.setVisibility(flag ? View.VISIBLE : View.GONE);
            view_line.setVisibility(flag ? View.VISIBLE : View.GONE);
            rl_wdt_remark.setVisibility(flag ? View.VISIBLE : View.GONE);
            rl_wdt_order.setVisibility(View.GONE);
            //ETH获奖单独处理
            if ("200".equals(bgtInfoBean.getTradeTypeId())) {
                tv_wdt_draw_title.setVisibility(View.VISIBLE);
                tv_wdt_draw_title.setText("订单详情:");
                rl_wdt_order.setVisibility(View.VISIBLE);
                tv_wdt_apply_name.setText("订单时间");
                tv_wdt_remark_title.setText("活动期号");
                rl_wdt_remark.setVisibility(View.VISIBLE);
            }
            //申请处理时间  暂时不使用
            rl_wdt_deal_time.setVisibility(View.GONE);
        }
        //ETH消费, 购买赠送BGT, 版本更新
        if ("501".equals(bgtInfoBean.getTradeTypeId())
                || "503".equals(bgtInfoBean.getTradeTypeId())
                || "504".equals(bgtInfoBean.getTradeTypeId())
                || "500".equals(bgtInfoBean.getTradeTypeId())
                || "402".equals(bgtInfoBean.getTradeTypeId())) {
            tv_wdt_draw_title.setVisibility(View.VISIBLE);
            tv_wdt_draw_title.setText("订单详情:");
            rl_wdt_order.setVisibility(View.VISIBLE);
            tv_wdt_apply_name.setText("500".equals(bgtInfoBean.getTradeTypeId()) ? "充值时间: " : "订单时间");
            tv_wdt_remark_title.setText("备注");
            rl_wdt_remark.setVisibility(View.VISIBLE);
        }
        //分红
        if ("550".equals(bgtInfoBean.getTradeTypeId())
                || "600".equals(bgtInfoBean.getTradeTypeId())
                || "601".equals(bgtInfoBean.getTradeTypeId())) {
            tv_wdt_draw_title.setVisibility(View.GONE);
            rl_wdt_order.setVisibility(View.GONE);
            tv_wdt_apply_name.setText("订单时间");
            tv_wdt_remark_title.setText("备注");
            rl_wdt_remark.setVisibility(View.VISIBLE);
        }
    }

    /**
     * 设置界面数据
     */
    @SuppressLint("SetTextI18n")
    private void setViewData() {
        tv_wdt_apply_time.setText(bgtInfoBean.getCreateTime());
        tv_wdt_details.setText(bgtInfoBean.getTradeTypeName());
        tv_wdt_name.setText(bgtInfoBean.getWallteTypeName());
        //提现地址
        tv_wdt_address.setText(bgtInfoBean.getWallteAddr());
        //处理时间
        tv_wdt_deal_time.setText("--");
        //活动期号/备注
        tv_wdt_remark.setText(bgtInfoBean.getFlowDesc());
        //订单编号
        tv_wdt_order_num.setText(bgtInfoBean.getRelationOrderNo());

        //加减标识
        String inOutFlag = bgtInfoBean.getInOutFlag() == 0 ? "+" : "-";

        tv_wdt_num.setText(inOutFlag + df.format(bgtInfoBean.getOptNum()));
        tv_wdt_type.setText(bgtInfoBean.getInOutFlag() == 0 ? "已到账" : "已支出");
    }
}
